package com.subaiqiao.yunshiyuan.entrance.ysy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subaiqiao.yunshiyuan.basis.controller.BasisController;
import com.subaiqiao.yunshiyuan.basis.utils.Result;
import com.subaiqiao.yunshiyuan.entrance.ysy.pojo.VerificationCode;
import com.subaiqiao.yunshiyuan.entrance.ysy.service.VerificationCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 曹朝禹
 * @since 2022-05-13
 */
@RestController
@RequestMapping("/ysy/verification-code")
@Api(tags = "验证码信息")
public class VerificationCodeController extends BasisController<VerificationCode, VerificationCodeService> {

    @Override
    public VerificationCodeService getService() {
        return verificationCodeService;
    }

    @Autowired
    private VerificationCodeService verificationCodeService;

    @ApiOperation("分页查询验证码信息")
    @GetMapping("/FindVerificationCodePage.do")
    public Result FindVerificationCodePage(
            @RequestParam @ApiParam("页码") Integer pageNum,
            @RequestParam @ApiParam("数量") Integer pageSize,
            @RequestParam(defaultValue = "") @ApiParam("接收号码") String vfReception,
            @RequestParam(defaultValue = "") @ApiParam("业务类型") String vfOperation,
            @RequestParam(defaultValue = "") @ApiParam("验证码类型") Integer vfType
    ){
        QueryWrapper<VerificationCode> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("create_datetime");
        if(vfReception!=null) wrapper.like("vf_reception",vfReception);
        if(vfOperation!=null) wrapper.like("vf_operation",vfOperation);
        if(vfType!=null) wrapper.eq("vf_type", vfType);
        IPage<VerificationCode> page = new Page<>(pageNum, pageSize);
        return Result.success(verificationCodeService.page(page,wrapper));
    }

    @ApiOperation("查询验证码详情")
    @GetMapping("/FindVerificationCodeDetail.do")
    public Result FindVerificationCodeDetail(@RequestParam @ApiParam("验证码编号") Integer verificationCodeId){
        return Result.success(verificationCodeService.getById(verificationCodeId));
    }

    @ApiOperation("查询所有验证码数量")
    @GetMapping("/FindVerificationCodeCount.do")
    public Result FindVerificationCodeCount(){
        return Result.success(verificationCodeService.FindVerificationCodeCount());
    }

    @ApiOperation("查询所有短信验证码数量")
    @GetMapping("/FindSMSVerificationCodeCount.do")
    public Result FindSMSVerificationCodeCount(){
        return Result.success(verificationCodeService.FindSMSVerificationCodeCount());
    }

    @ApiOperation("查询所有邮件验证码数量")
    @GetMapping("/FindEmailVerificationCodeCount.do")
    public Result FindEmailVerificationCodeCount(){
        return Result.success(verificationCodeService.FindEmailVerificationCodeCount());
    }

    @ApiOperation("查询昨日发送验证码总量")
    @GetMapping("/FindVerificationYesterdayRegister.do")
    public Result FindVerificationYesterdayRegister(){
        return Result.success(verificationCodeService.FindVerificationYesterdayRegister());
    }



}
